package com.example.liang.basamovie.utils;


import android.content.Context;
import android.widget.ImageView;

import com.example.liang.basamovie.R;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

/**
 * 图片下载的工具类
 */
public class ImageLoaderCircleUtils {
    static ImageLoader imageLoader;
    public static void getimage(Context context, String url, ImageView imageView){
        imageLoader= ImageLoader.getInstance();
        //图片存放的目录
        File cachedir= StorageUtils.getOwnCacheDirectory(context,"mnt/sdcard");
        ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(context).
                memoryCacheExtraOptions(200,300)
                .threadPoolSize(10)
                .imageDownloader(new BaseImageDownloader(context,5000,5000))
                .discCache(new UnlimitedDiscCache(cachedir))//存到指定目录
                .build();
        imageLoader.init(configuration);//初始化
        DisplayImageOptions option=new DisplayImageOptions.Builder().
                showImageOnFail(R.drawable.ysf_unsupport_mime_type)
                .showImageOnLoading(R.drawable.ysf_unsupport_mime_type)
                .cacheInMemory(true)
                .cacheOnDisc(true)
                .displayer(new RoundedBitmapDisplayer(360))//设置图片圆角
                .build();
        imageLoader.displayImage(url,imageView,option);//执行下载
    }




}
